package happywing.client.widget;

import happywing.client.Stage;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.TextBox;

public class LoginView extends Composite {
	private Image backgroundImage = new Image();
	private TextBox username = new TextBox();
	private TextBox password = new TextBox();
	private Button button=new Button();
	private Image image = new Image();
	private CheckBox check = new CheckBox("记住密码");
	
	public LoginView(){
		username.setText("用户名");
	    password.setText("密码");
	    button.setText("登录");
	    
	    button.addClickHandler(new ClickHandler() {
	        public void onClick(ClickEvent event) {
	        	Stage.get().dropLoginView();
	        }
	      });
	    
	    image.setStyleName("face");
	    image.setUrl("/pics/face.jpg");
	    
	    backgroundImage.setUrl("/images/loginbg.jpg");
	    backgroundImage.setWidth("100%");
	    backgroundImage.setHeight("100%");
	    
	    LayoutPanel loginPanel=new LayoutPanel();
		loginPanel.setStyleName("loginPanel");
		
		loginPanel.add(image);
		loginPanel.add(username);
		loginPanel.add(password);
		loginPanel.add(button);
		loginPanel.add(check);

		loginPanel.setWidgetLeftWidth(image, 0, Unit.EM, 5, Unit.EM);
		loginPanel.setWidgetTopHeight(image, 0, Unit.EM, 5, Unit.EM);
		loginPanel.setWidgetRightWidth(username, 0, Unit.EM, 15, Unit.EM);
		loginPanel.setWidgetTopHeight(username, 0, Unit.EM, 2, Unit.EM);
		loginPanel.setWidgetRightWidth(password, 0, Unit.EM, 15, Unit.EM);
		loginPanel.setWidgetTopHeight(password, 2.1, Unit.EM, 2, Unit.EM);
		loginPanel.setWidgetRightWidth(check, 5, Unit.EM, 6, Unit.EM);
		loginPanel.setWidgetTopHeight(check, 5.3, Unit.EM, 2, Unit.EM);
		loginPanel.setWidgetRightWidth(button, 0, Unit.EM, 4, Unit.EM);
		loginPanel.setWidgetTopHeight(button, 5, Unit.EM, 2, Unit.EM);
		
		
		LayoutPanel loginView=new LayoutPanel();
		loginView.add(backgroundImage);
		loginView.add(loginPanel);
		
		loginView.setWidgetLeftRight(backgroundImage, 0, Unit.PX, 0, Unit.PX);
		loginView.setWidgetTopBottom(backgroundImage, 0, Unit.PX, 0, Unit.PX);
		loginView.setWidgetBottomHeight(loginPanel, 8, Unit.EM, 8, Unit.EM);
		
		initWidget(loginView);
	    setStyleName("loginView");
	}
}
